<?php

namespace app\api\controller;

use app\admin\model\Banner;
use app\admin\model\Search;
use app\admin\model\Shop;
use app\admin\model\Specs;
use app\admin\model\Store;
use app\common\controller\Api;
use app\common\model\Category;
use app\common\model\Config;

/**
 * 首页接口weigh
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $this->success('请求成功');
    }

    /*
     * 轮播管理
     * */
    public function bannerList(){
      $list = Banner::order("weigh asc")->select();
      $data["list"]  =$list;
      $data["fileUrl"]  =Config::where("name","file_url")->value("value");
      return $this->success("成功",$data);
    }
    /*
     * 商品管理
     * */
    public function shopList(){
        if($this->request->isPost()){
            $where = $this->request->post();
            $where["status"]  =1 ;
            $list = Shop::where($where)->order("weigh asc")->limit(6)->select();
            $data["fileUrl"]  =Config::where("name","file_url")->value("value");
            $data["list"]  = $list;
            return $this->success("成功",$data);
        }
        return $this->success("请求成功");
    }
    public function shopListPage(){
        if($this->request->isPost()){
            $where["status"]  =1 ;
            if($this->request->post("name")!=""){
                $where["name"]  =["like","%".$this->request->post("name")."%"] ;
            }
            if($this->request->post("type")!=""){
                $where["category_id"]  =$this->request->post("type");
            }
            $list = Shop::where($where)->order($this->request->post("sort"))->select();






            $data["fileUrl"]  =Config::where("name","file_url")->value("value");
            $data["list"]  = $list;
            return $this->success("成功",$data);
        }
        return $this->success("请求成功");
    }
    /*
     * 商品信息表
     * */
    public function shopInfo(){
        if($this->request->isPost()){
            $where = $this->request->post();
            $where["status"]  =1 ;
            $where["id"]  =$this->request->post("id") ;
            $data = Shop::where($where)->find();
            $data["host"] = Config::where("name","file_url")->value("value");

            //查找规格
            $data['spec_data'] =  Specs::where("status",1)->where("shop_id",$where["id"])->select();
            $data['storeInfo'] =  Store::where("id",1)->find();


            return $this->success("成功",$data);
        }
        return $this->success("请求成功");
    }

    /*
     * 商品分  类管理
     * */
    public function cateList(){
        if($this->request->isPost()){
            $where["status"]  ="normal";
            $list = Category::where($where)->order("weigh asc")->select();
            return $this->success("成功",$list);
        }
        return $this->success("请求成功");
    }

    public function searchList(){
            $data = Search::select();
            $arr = [];
            foreach ($data as $v){
                $arr[] = $v['name'];
            }
        return $this->success("成功",$arr);
    }


    public function storeInfo(){
        $info =  Store::where("id",1)->find();
        $info["host"]  =Config::where("name","file_url")->value("value");

        return $this->success("成功",$info);
    }

}
